# -*- encoding:utf8 -*-

import MySQLdb

db = MySQLdb.connect("localhost","root","zsx123456","python_db",charset='utf8')

cursor = db.cursor()

sql = '''
select * from employee
'''

try:
    cursor.execute(sql)
    result = cursor.fetchall()
    for item in result:
        fname = item[0]
        lname = item[1]
        age = item[2]
        gender = item[3]
        income = item[4]
        print "查询结果:姓:",lname,"，名:",fname,",年龄:",age,",性别:",gender,",收入:",income
except Exception,e:
    print "查询异常，原因:",e

finally:
    print "关闭数据库连接"
    db.close()
